<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="" prop="siteId">-->
<!--        <el-input-->
<!--          v-model="queryParams.siteId"-->
<!--          placeholder="请输入"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="语言" prop="langId">-->
<!--        <el-input-->
<!--          v-model="queryParams.langId"-->
<!--          placeholder="请输入语言"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="短剧" prop="vid">-->
<!--        <el-input-->
<!--          v-model="queryParams.vid"-->
<!--          placeholder="请输入短剧"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="名称" prop="name">-->
<!--        <el-input-->
<!--          v-model="queryParams.name"-->
<!--          placeholder="请输入名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="时长" prop="duration">-->
<!--        <el-input-->
<!--          v-model="queryParams.duration"-->
<!--          placeholder="请输入时长"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="价格" prop="price">-->
<!--        <el-input-->
<!--          v-model="queryParams.price"-->
<!--          placeholder="请输入价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="VIP价格" prop="vprice">-->
<!--        <el-input-->
<!--          v-model="queryParams.vprice"-->
<!--          placeholder="请输入VIP价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="销量" prop="sales">-->
<!--        <el-input-->
<!--          v-model="queryParams.sales"-->
<!--          placeholder="请输入销量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="点赞量" prop="likes">-->
<!--        <el-input-->
<!--          v-model="queryParams.likes"-->
<!--          placeholder="请输入点赞量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="播放量" prop="views">-->
<!--        <el-input-->
<!--          v-model="queryParams.views"-->
<!--          placeholder="请输入播放量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="收藏量" prop="favorites">-->
<!--        <el-input-->
<!--          v-model="queryParams.favorites"-->
<!--          placeholder="请输入收藏量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="转发量" prop="shares">-->
<!--        <el-input-->
<!--          v-model="queryParams.shares"-->
<!--          placeholder="请输入转发量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟点赞量" prop="fakeLikes">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeLikes"-->
<!--          placeholder="请输入虚拟点赞量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟播放量" prop="fakeViews">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeViews"-->
<!--          placeholder="请输入虚拟播放量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟收藏量" prop="fakeFavorites">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeFavorites"-->
<!--          placeholder="请输入虚拟收藏量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟转发量" prop="fakeShares">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeShares"-->
<!--          placeholder="请输入虚拟转发量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="排序" prop="weigh">-->
<!--        <el-input-->
<!--          v-model="queryParams.weigh"-->
<!--          placeholder="请输入排序"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新时间" prop="updatetime">-->
<!--        <el-input-->
<!--          v-model="queryParams.updatetime"-->
<!--          placeholder="请输入更新时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="添加时间" prop="createtime">-->
<!--        <el-input-->
<!--          v-model="queryParams.createtime"-->
<!--          placeholder="请输入添加时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="删除时间" prop="deletetime">-->
<!--        <el-input-->
<!--          v-model="queryParams.deletetime"-->
<!--          placeholder="请输入删除时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="episodesList" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="" align="center" prop="siteId" />
      <el-table-column label="语言" align="center" prop="langId" />
      <el-table-column label="短剧" align="center" prop="vid" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="封面" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="视频" width="280px" align="center" prop="video" />
      <el-table-column label="时长" align="center" prop="duration" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="VIP价格" align="center" prop="vprice" />
      <el-table-column label="销量" align="center" prop="sales" />
      <el-table-column label="点赞量" align="center" prop="likes" />
      <el-table-column label="播放量" align="center" prop="views" />
      <el-table-column label="收藏量" align="center" prop="favorites" />
      <el-table-column label="转发量" align="center" prop="shares" />
      <el-table-column label="虚拟点赞量" align="center" prop="fakeLikes" />
      <el-table-column label="虚拟播放量" align="center" prop="fakeViews" />
      <el-table-column label="虚拟收藏量" align="center" prop="fakeFavorites" />
      <el-table-column label="虚拟转发量" align="center" prop="fakeShares" />
      <el-table-column label="排序" align="center" prop="weigh" />
      <el-table-column label="商品状态:normal=显示,hidden=隐藏" align="center" prop="status" />
      <el-table-column label="更新时间" align="center" prop="updatetime" />
      <el-table-column label="添加时间" align="center" prop="createtime" />
      <el-table-column label="删除时间" align="center" prop="deletetime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改剧集对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="" prop="siteId">
          <el-input v-model="form.siteId" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="语言" prop="langId">
          <el-input v-model="form.langId" placeholder="请输入语言" />
        </el-form-item>
        <el-form-item label="短剧" prop="vid">
          <el-input v-model="form.vid" placeholder="请输入短剧" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="封面" prop="image">
          <image-upload v-model="form.image"/>
        </el-form-item>
        <el-form-item label="视频" prop="video">
          <file-upload v-model="form.video"/>
        </el-form-item>
        <el-form-item label="时长" prop="duration">
          <el-input v-model="form.duration" placeholder="请输入时长" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="VIP价格" prop="vprice">
          <el-input v-model="form.vprice" placeholder="请输入VIP价格" />
        </el-form-item>
        <el-form-item label="销量" prop="sales">
          <el-input v-model="form.sales" placeholder="请输入销量" />
        </el-form-item>
        <el-form-item label="点赞量" prop="likes">
          <el-input v-model="form.likes" placeholder="请输入点赞量" />
        </el-form-item>
        <el-form-item label="播放量" prop="views">
          <el-input v-model="form.views" placeholder="请输入播放量" />
        </el-form-item>
        <el-form-item label="收藏量" prop="favorites">
          <el-input v-model="form.favorites" placeholder="请输入收藏量" />
        </el-form-item>
        <el-form-item label="转发量" prop="shares">
          <el-input v-model="form.shares" placeholder="请输入转发量" />
        </el-form-item>
        <el-form-item label="虚拟点赞量" prop="fakeLikes">
          <el-input v-model="form.fakeLikes" placeholder="请输入虚拟点赞量" />
        </el-form-item>
        <el-form-item label="虚拟播放量" prop="fakeViews">
          <el-input v-model="form.fakeViews" placeholder="请输入虚拟播放量" />
        </el-form-item>
        <el-form-item label="虚拟收藏量" prop="fakeFavorites">
          <el-input v-model="form.fakeFavorites" placeholder="请输入虚拟收藏量" />
        </el-form-item>
        <el-form-item label="虚拟转发量" prop="fakeShares">
          <el-input v-model="form.fakeShares" placeholder="请输入虚拟转发量" />
        </el-form-item>
        <el-form-item label="排序" prop="weigh">
          <el-input v-model="form.weigh" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="删除时间" prop="deletetime">
          <el-input v-model="form.deletetime" placeholder="请输入删除时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getEpisodesList, getEpisodes, delEpisodes, addEpisodes, updateEpisodes } from "@/api/video/episodes";

export default {
  name: "Episodes",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 剧集表格数据
      episodesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        siteId: null,
        langId: null,
        vid: null,
        name: null,
        image: null,
        video: null,
        duration: null,
        price: null,
        vprice: null,
        sales: null,
        likes: null,
        views: null,
        favorites: null,
        shares: null,
        fakeLikes: null,
        fakeViews: null,
        fakeFavorites: null,
        fakeShares: null,
        weigh: null,
        status: null,
        updatetime: null,
        createtime: null,
        deletetime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        siteId: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        langId: [
          { required: true, message: "语言不能为空", trigger: "blur" }
        ],
        vid: [
          { required: true, message: "短剧不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        image: [
          { required: true, message: "封面不能为空", trigger: "blur" }
        ],
        video: [
          { required: true, message: "视频不能为空", trigger: "blur" }
        ],
        duration: [
          { required: true, message: "时长不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "价格不能为空", trigger: "blur" }
        ],
        vprice: [
          { required: true, message: "VIP价格不能为空", trigger: "blur" }
        ],
        sales: [
          { required: true, message: "销量不能为空", trigger: "blur" }
        ],
        likes: [
          { required: true, message: "点赞量不能为空", trigger: "blur" }
        ],
        views: [
          { required: true, message: "播放量不能为空", trigger: "blur" }
        ],
        favorites: [
          { required: true, message: "收藏量不能为空", trigger: "blur" }
        ],
        shares: [
          { required: true, message: "转发量不能为空", trigger: "blur" }
        ],
        fakeLikes: [
          { required: true, message: "虚拟点赞量不能为空", trigger: "blur" }
        ],
        fakeViews: [
          { required: true, message: "虚拟播放量不能为空", trigger: "blur" }
        ],
        fakeFavorites: [
          { required: true, message: "虚拟收藏量不能为空", trigger: "blur" }
        ],
        fakeShares: [
          { required: true, message: "虚拟转发量不能为空", trigger: "blur" }
        ],
        weigh: [
          { required: true, message: "排序不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "商品状态:normal=显示,hidden=隐藏不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询剧集列表 */
    getList() {
      this.loading = true;
      getEpisodesList(this.queryParams).then(response => {
        this.episodesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        siteId: null,
        langId: null,
        vid: null,
        name: null,
        image: null,
        video: null,
        duration: null,
        price: null,
        vprice: null,
        sales: null,
        likes: null,
        views: null,
        favorites: null,
        shares: null,
        fakeLikes: null,
        fakeViews: null,
        fakeFavorites: null,
        fakeShares: null,
        weigh: null,
        status: null,
        updatetime: null,
        createtime: null,
        deletetime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加剧集";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEpisodes(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改剧集";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEpisodes(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEpisodes(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除剧集编号为"' + ids + '"的数据项？').then(function() {
        return delEpisodes(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/episodes/export', {
        ...this.queryParams
      }, `episodes_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>

</style>
